package com.hxd.service;

import com.hxd.dao.UserDao;
import com.hxd.pojo.Page;
import com.hxd.pojo.Users;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    UserDao userDao;
    //根据登录账号查询员工信息
    public Users selectUser(String username){
        return userDao.queryuser(username);
    }
    //插入员工信息
    public int insertuser(Users users) {
        int insertuser = userDao.insertuser(users);
        return insertuser;
    }

    //查询所有员工信息
    public Page<Users> selectAlluser(int pagenum) {
        Page<Users> page = new Page<>();
        page.setPagenum(pagenum);

        //查询所有员工信息条数
        int totalRows = userDao.selectAlluser();
        page.setTotalRows(totalRows);

        //全部信息分页查询
        List<Users> datas = userDao.selectPage(page);
        page.setDates(datas);

        return page;
    }

    //按条件查询员工信息
    public Page<Users> selectOneuser(Users users, int pagenum) {
        Page<Users> page = new Page<>();
        page.setPagenum(pagenum);

        //按照条件查询信息条数
        int totalRows = userDao.selectOneusernum(users,page);
        page.setTotalRows(totalRows);

        //按条件查询员工信息
        List<Users> datas = userDao.selectOneuser(users,page);
        page.setDates(datas);

        return page;
    }

    //根据id查询员工
    public Users selectOne(int id) {
        return userDao.selectOne(id);
    }

    //修改员工信息
    public int updateuser(Users users) {
        int i = userDao.updateuser(users);
        return i;
    }

    //删除员工
    public int deleteUser(int id) {
        return userDao.deleteUser(id);
    }
}
